﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Royaumes_Libres.Database;
using System.Collections;

namespace Royaumes_Libres
{
    /// <summary>
    /// Affiche les buildings diponibles à construire et liste ceux déjà construit
    /// </summary>
    /// <remarks>Patrick Chabot</remarks>
    public partial class userbuilding : System.Web.UI.Page
    {
        cKingdom kingdom;
        cUsers pUser;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session[Properties.Settings.Default.ObjUser] != null)
            {
                this.pUser = (cUsers)Session[Properties.Settings.Default.ObjUser];
            }
            kingdom = new cKingdom(this.pUser.PkUser, this.pUser.ActiveWorld);
            this.Building_Load();
        }

        protected void Building_Load()
        {
            ArrayList uniqueBuild = new ArrayList();

            cOwnerBuildings[] oBuildings = kingdom.GetOwnerBuilding();
            foreach (cOwnerBuildings building in oBuildings)
            {
                this.divOwnership.Controls.Add(building.GetControl(Page));
                if (building.UniqueBuild)
                {
                    uniqueBuild.Add(building.Name);
                }
            }

            cBuildings[] buildings = kingdom.GetBuilding();
            ucBuilding ucB;
            foreach (cBuildings building in buildings)
            {
                if (!uniqueBuild.Contains(building.Name))
                {
                    ucB = building.GetControl(Page);
                    ucB.Ressource = kingdom.Ressource;
                    ucB.BuildingsBuilds = kingdom.GetBuildingsBuilds();
                    this.divBuildings.Controls.Add(ucB);
                }
            }
        }
    }
}